#!/bin/sh

function getVersion
{
  DAY=$(date '+%d')
  MONTH=$(date '+%m')
  YEAR=$(date '+%y')
}

echo "Building Ynbw 3"

make clean
if [ $? != "0" ]
then
  exit -2
fi

sudo make uninstall
if [ $? != "0" ]
then
  exit -1
fi

echo -n "Version to build as: "
read version

version="$version.$YEAR$MONTH$DAY"

echo -n "Should I tag the repo [Yn]? "
read tag

case "$tag" in
  y|Y) hg tag "Version_$version";;
  *);;
esac

echo -n "Should I push the repo [Yn]? "
read push

case "$push" in
  y|Y) hg push;;
  *);;
esac

make debug VERSION=$version
if [ $? != "0" ]
then
  exit 1
fi

make VERSION=$version
if [ $? != "0" ]
then
  exit 2
fi

make archive.src VERSION=$version
if [ $? != "0" ]
then
  exit 3
fi

make archive.bin VERSION=$version
if [ $? != "0" ]
then
  exit 5
fi

sudo make install
if [ $? != "0" ]
then
  exit 4
fi

exit 0
